<?php
require dirname(__DIR__).'/unit_test_conf.php';
require __DIR__.'/Class.php';
define('NAME', basename(__DIR__));

/**
 *	
 */
class UnitTest extends PHPUnit_Framework_TestCase
{
	################################################################################################################################
	#	1. Setting Basic varialbes for Testing..
	################################################################################################################################
	protected static $error;
	protected static $user_seq;
	
	################################################################################################################################
	#	2. Basic Method Testing..
	################################################################################################################################

	/**
	 * 
	 */
	public function testInsert4Class()
	{
		try
		{
			$o = Wdk::get(NAME);
			$o['user_login_id']		= 'id_'.utRc(3);
			$o['user_login_passwd']	= utRc(rand(7,12));
			$o['fk_user_group_seq']	= rand(1,10);
			$o['user_name']			= 'name:'.utRc(rand(5,10));
			$o['user_nick']			= 'nick:'.utRc(rand(5,10));
			$o['user_icon']			= date('Ymd').sha1(utRc(rand(5,10)));
			$o['user_birth_date']	= '19'.rand(70,90).'-'.rand(10,12).'-'.rand(10,31);
			$o['user_email']		= utRc(rand(5,8)).'@gmail.com';
			$o['user_phone']		= rand(100,999).'-'.rand(1000,9999).'-'.rand(1000,9999);
			$o['user_mobile']		= rand(100,999).'-'.rand(1000,9999).'-'.rand(1000,9999);
			$o['user_sex']			= utRand(USER_SEX_MALE,USER_SEX_FEMALE);
			$o['user_memo']			= utRc(rand(10,40));
			$o['user_info_public']	= utRand('T','F');
			$o->insert();

			$pwd = Wdk::helper('Passwd');
			$o['user_login_passwd'] = $pwd->decrypt($o['user_login_passwd']);
				
			self::$user_seq = $o['user_seq'];
			/************************************************************************************************************************/
			//	Compare Both Data..
			/************************************************************************************************************************/
			$c = Wdk::get(NAME);
			$c->load(self::$user_seq);

			$this->assertEquals($o['user_login_id']			, $c['user_login_id']			, "[Error] user_login_id");
			$this->assertEquals($o['user_login_passwd']		, $c['user_login_passwd_str']	, "[Error] user_login_passwd");
			$this->assertEquals($o['fk_user_group_seq']		, $c['fk_user_group_seq']		, "[Error] fk_user_group_seq");
			$this->assertEquals($o['user_name']				, $c['user_name']				, "[Error] user_name");
			$this->assertEquals($o['user_nick']				, $c['user_nick']				, "[Error] user_nick");
			$this->assertEquals($o['user_icon']				, $c['user_icon']				, "[Error] user_icon");
			$this->assertEquals($o['user_birth_date']		, $c['user_birth_date']			, "[Error] user_birth_date");
			$this->assertEquals($o['user_email']			, $c['user_email']				, "[Error] user_email");
			$this->assertEquals($o['user_phone']			, $c['user_phone']				, "[Error] user_phone");
			$this->assertEquals($o['user_mobile']			, $c['user_mobile']				, "[Error] user_mobile");
			$this->assertEquals($o['user_sex']				, $c['user_sex']				, "[Error] user_sex");
			$this->assertEquals($o['user_memo']				, $c['user_memo']				, "[Error] user_memo");
			$this->assertEquals($o['user_info_public']		, $c['user_info_public']		, "[Error] user_info_public");
			$this->assertEquals($o['user_validate_time']	, $c['user_validate_time']		, "[Error] user_validate_time");
			$this->assertEquals($o['user_insert_time']		, $c['user_insert_time']		, "[Error] user_insert_time");
			$this->assertEquals('F'							, $c['user_del_flag']			, "[Error] user_del_flag");
			/************************************************************************************************************************/
		}
		catch(WException $e)
		{
			self::$error = true;
			$this->assertTrue(False, 'Exception - '.$e->getMessage());
		}
	}
	
	
	/**
	 *	
	 */
	public function testUpdate4Class()
	{
		if(self::$error == true) return;
		try
		{
			$o = Wdk::get(NAME);
			$o->load(self::$user_seq);
			$o['user_login_passwd']	= utRc(rand(7,12));
			$o['fk_user_group_seq']	= rand(1,10);
			$o['user_name']			= 'name:'.utRc(rand(5,10));
			$o['user_nick']			= 'nick:'.utRc(rand(5,10));
			$o['user_icon']			= date('Ymd').sha1(utRc(rand(5,10)));
			$o['user_birth_date']	= '19'.rand(70,90).'-'.rand(10,12).'-'.rand(10,31);
			$o['user_email']		= utRc(rand(5,8)).'@gmail.com';
			$o['user_phone']		= rand(100,999).'-'.rand(1000,9999).'-'.rand(1000,9999);
			$o['user_mobile']		= rand(100,999).'-'.rand(1000,9999).'-'.rand(1000,9999);
			$o['user_sex']			= utRand(USER_SEX_MALE,USER_SEX_FEMALE);
			$o['user_memo']			= utRc(rand(10,40));
			$o['user_info_public']	= utRand('T','F');
			$o->update();
			
			$pwd = Wdk::helper('Passwd');
			$o['user_login_passwd'] = $pwd->decrypt($o['user_login_passwd']);
			
			/************************************************************************************************************************/
			//	Compare Both Data..
			/************************************************************************************************************************/
			$c = Wdk::get(NAME);
			$c->load(self::$user_seq);
			$this->assertEquals($o['user_login_id']			, $c['user_login_id']			, "[Error] user_login_id");
			$this->assertEquals($o['user_login_passwd']		, $c['user_login_passwd_str']	, "[Error] user_login_passwd");
			$this->assertEquals($o['fk_user_group_seq']		, $c['fk_user_group_seq']		, "[Error] fk_user_group_seq");
			$this->assertEquals($o['user_name']				, $c['user_name']				, "[Error] user_name");
			$this->assertEquals($o['user_birth_date']		, $c['user_birth_date']			, "[Error] user_birth_date");
			$this->assertEquals($o['user_nick']				, $c['user_nick']				, "[Error] user_nick");
			$this->assertEquals($o['user_icon']				, $c['user_icon']				, "[Error] user_icon");
			$this->assertEquals($o['user_email']			, $c['user_email']				, "[Error] user_email");
			$this->assertEquals($o['user_phone']			, $c['user_phone']				, "[Error] user_phone");
			$this->assertEquals($o['user_mobile']			, $c['user_mobile']				, "[Error] user_mobile");
			$this->assertEquals($o['user_sex']				, $c['user_sex']				, "[Error] user_sex");
			$this->assertEquals($o['user_memo']				, $c['user_memo']				, "[Error] user_memo");
			$this->assertEquals($o['user_info_public']		, $c['user_info_public']		, "[Error] user_info_public");
			/************************************************************************************************************************/
		}
		catch(WException $e)
		{
			self::$error = true;
			$this->assertTrue(False, 'Exception - '.$e->getMessage());
		}
	}
	
	
	/**
	 *	
	 */
	public function testLoadByLoginId4Class()
	{
		if(self::$error == true) return;
		try
		{
			$c = Wdk::get(NAME);
			$c->load(self::$user_seq);
			$c->loadByLoginId($c['user_login_id']);
		}
		catch(WException $e)
		{
			self::$error = true;
			$this->assertTrue(False, 'Exception - '.$e->getMessage());
		}
	}
	
	################################################################################################################################
	#	3. Manager Method Testing..
	################################################################################################################################
	/**
	 * 
	 */
	public function testLoad4Manager()
	{
		if(self::$error == true) return;
		try
		{
			$cm = Wdk::get(NAME.'Manager');
			$cm->load();
		}
		catch(NoRecordException $e){}
		catch(WException $e)
		{
			self::$error = true;
			$this->assertTrue(False, 'Exception - '.$e->getMessage());
		}
	}
	
	################################################################################################################################
	#	4. Scenario Testing..
	#	-> a)
	################################################################################################################################
	
	################################################################################################################################
	#	5. Testing tool Methods
	################################################################################################################################
	private function removeTestData()
	{

	}
	public function setUp()
	{
		//	no need..
	}
	public function tearDown()
	{
		//	no need..
	}
	################################################################################################################################
}
?>